package com.xmotor.test_cookie;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;

/**
 * @Description
 * @Author Dang Xianyue
 * @Date 2020-10-19 08:54
 * @Version 1.0
 */
@Controller
@RequestMapping("/test_cookie")
public class TestCookieController {


    //localhost:8090/test-spring-boot/test_cookie/test1
    @RequestMapping("/test1")
    public ModelAndView test1() throws Exception{
        System.out.println("test1接口");
        return new ModelAndView("redirect:/test_cookie/test2");
    }


    @RequestMapping("/test2")
    public ModelAndView test2(HttpServletResponse response) throws Exception{
        System.out.println("test2接口");
//        CookieUtil.addCookie(response,"token_test2","jaoigjhiaop",-1);
        CookieUtil.addCookie(response,"token_test2","jaoigjhiaop","localhost");
        return new ModelAndView("redirect:http://www.baidu.com");
    }

    @RequestMapping("/test3")
    @ResponseBody
    public String test3(HttpServletResponse response) throws Exception{
        System.out.println("test3接口");
        CookieUtil.addCookie(response,"token_test3","jaoigjhiaop",-1);
        return "test3";
    }

}
